package com.foreknow.view;

import com.foreknow.model.Business;
import com.foreknow.service.BusinessService;
import com.foreknow.service.impl.BusinessServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Addinfo extends JFrame {

    private JPanel contentPane;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Addinfo frame = new Addinfo();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Addinfo() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 754, 518);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel lblNewLabel = new JLabel("password");
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
        lblNewLabel.setBounds(101, 69, 120, 31);
        contentPane.add(lblNewLabel);

        JLabel lblBussin = new JLabel("businessName");
        lblBussin.setFont(new Font("宋体", Font.PLAIN, 20));
        lblBussin.setBounds(101, 122, 120, 31);
        contentPane.add(lblBussin);

        JLabel lblBusinessadd = new JLabel("businessAddress");
        lblBusinessadd.setFont(new Font("宋体", Font.PLAIN, 20));
        lblBusinessadd.setBounds(101, 175, 165, 31);
        contentPane.add(lblBusinessadd);

        JLabel lblBusinessex = new JLabel("businessExplain");
        lblBusinessex.setFont(new Font("宋体", Font.PLAIN, 20));
        lblBusinessex.setBounds(101, 232, 165, 31);
        contentPane.add(lblBusinessex);

        JLabel lblStarprice = new JLabel("starPrice");
        lblStarprice.setFont(new Font("宋体", Font.PLAIN, 20));
        lblStarprice.setBounds(101, 293, 92, 31);
        contentPane.add(lblStarprice);

        JLabel lblDeliver = new JLabel("deliverPrice");
        lblDeliver.setFont(new Font("宋体", Font.PLAIN, 20));
        lblDeliver.setBounds(101, 355, 120, 31);
        contentPane.add(lblDeliver);

        textField = new JTextField();
        textField.setBounds(295, 68, 298, 36);
        contentPane.add(textField);
        textField.setColumns(10);

        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(295, 117, 298, 36);
        contentPane.add(textField_1);

        textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(295, 170, 298, 36);
        contentPane.add(textField_2);

        textField_3 = new JTextField();
        textField_3.setColumns(10);
        textField_3.setBounds(295, 227, 298, 36);
        contentPane.add(textField_3);

        textField_4 = new JTextField();
        textField_4.setColumns(10);
        textField_4.setBounds(295, 288, 298, 36);
        contentPane.add(textField_4);

        textField_5 = new JTextField();
        textField_5.setColumns(10);
        textField_5.setBounds(295, 354, 298, 36);
        contentPane.add(textField_5);

        JButton btnNewButton = new JButton("\u786E\u5B9A");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                BusinessService business = new BusinessServiceImpl();
                String password=textField.getText();
                String  businessName=textField_1.getText();
                String businessAddress=textField_2.getText();
                String businessExplain=textField_3.getText();
                String starPrice=textField_4.getText();
               String deliveryPrice = textField_5.getText();
                double star = Double.parseDouble(starPrice);
                double delive=Double.parseDouble(deliveryPrice);

                Business b1=new Business();
                b1.setPassword(password);
                b1.setBusinessName(businessName);
                b1.setBusinessAddress(businessAddress);
                b1.setBusinessExplain(businessExplain);
                b1.setStarPrice(star);
                b1.setDeliveryPrice(delive);


                boolean add = business.add(b1);
                if(add){
                    MainWindow mainWindow=new MainWindow();
                    mainWindow.setVisible(true);
                    Addinfo.this.dispose();
                }

//                System.out.println("aaaaaaaaaaa");
            }
        });
        btnNewButton.setBounds(201, 420, 113, 27);
        contentPane.add(btnNewButton);

        JButton button = new JButton("\u53D6\u6D88");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MainWindow mainWindow = new MainWindow();
                mainWindow.setVisible(true);
                Addinfo.this.dispose();
            }
        });
        button.setBounds(459, 420, 113, 27);
        contentPane.add(button);
    }
}
